package panel.control;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import shape.Shape;
import window.Command;

public class GeneratePanel extends JPanel {
	ActionListener		actionControl;
	
	JComboBox<String>	list;
	JButton				generate, erase;
	JLabel				title;
	
	public GeneratePanel( ActionListener actionControl ) {
		GridBagConstraints c = new GridBagConstraints();
		
		setLayout(new GridBagLayout());
		setOpaque(false);
		
		this.actionControl = actionControl;
		
		c.insets 	= new Insets(0, 0, 5, 0);
		c.fill 		= GridBagConstraints.BOTH;
		c.gridx 	= 0;
		c.gridy 	= GridBagConstraints.RELATIVE;
		c.gridwidth = 2;
		c.weightx	= 1.0;
		c.weighty 	= 1.0;
		
		title = new JLabel("Shapes");
		add(title, c);
		
		list = new JComboBox<String>( new DefaultComboBoxModel<String>(Shape.SHAPE_NAME) );
		add( list, c );
		
		c.gridwidth = 1;
		c.insets.right = 2;
		
		generate = new JButton("Add");
		generate.setActionCommand(String.valueOf(Command.ADD_SHAPE));
		generate.addActionListener(actionControl);
		add(generate, c);
		
		c.gridx = 1;
		c.insets.right = 0;
		c.insets.left = 2;
		
		erase = new JButton("Del");
		erase.setActionCommand(String.valueOf(Command.DELETE_SHAPE));
		erase.addActionListener(actionControl);
		add(erase, c);
	}
	
	public int getSelectedShapeType() {
		return list.getSelectedIndex();
	}
}
